package com.etc.order.provider.mapper;

import com.etc.order.common.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Results(id = "userMap", value = {
            @Result(column = "uid", property = "uid"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "user_address", property = "userAddress"),
            @Result(column = "user_phone", property = "userPhone"),
            @Result(column = "user_password", property = "userPassword")
    })
    @Select("SELECT * FROM user")
    List<User> getAll();

    @Select("SELECT * FROM user t WHERE t.uid = #{id}")
    @ResultMap("userMap")
    User getOne(Long id);

    @Select("SELECT * FROM user t WHERE t.user_name = #{username}")
    @ResultMap("userMap")
    List<User> findByUsername(@Param("username") String username);

    @Update("UPDATE user SET user_name = #{user.userName}, " +
            "user_address = #{user.userAddress}, " +
            "user_phone = #{user.userPhone}, " +
            "user_password = #{user.userPassword} WHERE uid = #{user.uid}")
    int update(@Param("user") User user);
}
